package com.tanhua.server.intercepter;

import com.tanhua.model.domain.User;

//线程类
public class UserThreadLocal {

    //创建一个线程对象
    private static ThreadLocal<User> t1 = new ThreadLocal<User>();


   //1.保存用户数据到线程
    public static void set(User user) {
        t1.set(user);
    }

    //2.获取线程中的用户信息
    public static User get() {
        return t1.get();
    }

    //2.1获取当前用户id
    public static Long getUserId() {
        if (t1.get() == null) {
            return null;
        }
        return t1.get().getId();
    }

    //2.2获取当前用户电话
    public static String getPhone(){
        if (t1.get()==null){
            return null;
        }
        return t1.get().getMobile();
    }


     //2.3 移除线程中数据
    public static void remove() {
        t1.remove();
    }
}
